package com.itheima.service;

import com.itheima.bean.Admin;
import com.itheima.bean.Course;
import com.itheima.dao.AdminDao;

import java.io.IOException;
import java.util.ArrayList;

public class AdminService {
    private AdminDao adminDao = new AdminDao();

    public boolean istrue(String adminid, String apassword) throws IOException {
        ArrayList<Admin> admins = adminDao.redAdmin();
        boolean flag = false;
        for (Admin admin : admins) {
            if (adminid.equals(admin.getId()) || apassword.equals(admin.getPassword())) {
                return flag = true;
            }
        }
        return flag;
    }
    public boolean addcourse(Course course) throws IOException {

        return adminDao.addcourse(course);
    }

    public boolean isExits(String id) throws IOException {
        ArrayList<Course> id1 = adminDao.findId();
        boolean flag = false;
        for (Course course : id1) {
            if (id.equals(course.getCid())) {
                flag = true;
                break;
            }
        }
        return flag;
    }


    public void deletecourse(String id) throws IOException {
      adminDao.deletecourse(id);
    }

    public void findcourse() throws IOException {
        adminDao.findcourse();
    }
}
